<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%	
	//获取项目名
	String path = request.getContextPath();
	//获取tomcat 协议+地址+端口号+ 获取项目名
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	//out.println(basePath);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>网站后台管理模版</title>
<link rel="stylesheet" type="text/css"
	href="<%=basePath %>background/static/admin/layui/css/layui.css" />
<link rel="stylesheet" type="text/css"
	href="<%=basePath %>background/static/admin/css/admin.css" />
<script src="<%=basePath %>jquery-3.5.1.js"></script>
<script
	src="<%=basePath %>bootstrap/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
<link rel="stylesheet"
	href="<%=basePath %>bootstrap/bootstrap-3.3.7-dist/css/bootstrap.css">
<link rel="stylesheet"
	href="<%=basePath %>background/ordUserJs/css/modifyRs.css">
<link rel="stylesheet" href="../css/sweetalert.css">
<script src="../js/sweetalert-dev.js"></script>
</head>
<body>

	<div class="wrap-container">
		<form class="layui-form" style="width: 90%; padding-top: 20px;">
			
			<div class="layui-form-item">
				<label class="layui-form-label">修改院校省份：</label>
				<div class="layui-input-block">
					<input value="" id="cProvince" type="text" name="cProvince"
						autocomplete="off" class="layui-input">
				</div>

			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">修改院校名称：</label>
				<div class="layui-input-block">
					<input value="" id="cName" type="text" name="cName"
						autocomplete="off" class="layui-input">
				</div>

			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">修改院校校徽：</label>
				<div class="layui-input-block">
					<input value="" id="cLogo" type="text" name="cLogo"
						autocomplete="off" class="layui-input">
				</div>

			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<!--lay-submit lay-filter="formDemo"  -->
					<button id="sub" class="layui-btn layui-btn-normal">修改</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>
	<%
		String collegeid =  request.getParameter("collegeid");
		String collegeName =  request.getParameter("collegeName");
		String collegeProvince =  request.getParameter("collegeProvince");
		String collegeLogo =  request.getParameter("collegeLogo");
		
		%>

	<script type="text/javascript" charset="utf-8">
			var collegeid = <%=collegeid%>;
			var collegeName = <%=collegeName%>;
			var collegeProvince = <%=collegeProvince%>
			var collegeLogo = <%=collegeLogo%>
			console.log(collegeid,collegeName,collegeProvince,collegeLogo);
			
			$(function(){
				document.getElementById("cProvince").value = collegeProvince;
				document.getElementById("cName").value = collegeName;
				document.getElementById("cLogo").value = collegeLogo;
			}); 
		
			$("#sub").click(function(){
				
				var cProvince = $("#cProvince").val();
				var cName = $("#cName").val();
				var cLogo = $("#cLogo").val();
				console.log(cProvince,cName,cLogo);
				
				if(cProvince==null || cProvince==""){
					swal("请输入院校所属省份");
					return;
				}
				if(cName==null || cName==""){
					swal("院校名不能为空！");
					return;
				}
				if(cLogo==null || cLogo==""){
					swal("校徽不能为空！");
					return;
				}
				
				$.ajax({
					url:"<%=basePath %>BackCollegeServlet",
					type:"get",
					data:"mark=modifyCollege&collegeid="+collegeid+"&collegeProvince="+cProvince+"&collegeName="+cName+"&collegeLogo="+cLogo,
					dataType:"json",
					success:function(mes){
						console.log(mes);
						if(mes==true){
							alert("修改成功！");
							window.location.href = "<%=basePath %>mark=BackCollegeServlet?mark=showCollege";
							
						}else{
							alert("修改失败！");
							return;
						}
					},
					error:function(mes){ // 这里是有bug的，但是为了能够跳转到展示页面，只好这么做了，
						//但还有个缺点是可以跳转，但不能及时刷新
				    	  if(mes!=null){
				    		  	console.log("是true");
								swal("修改成功",cName,"success")
								window.location.href = "<%=basePath %>BackCollegeServlet?mark=showCollege";
								
							}else{
								console.log("是false");
								alert("修改失败！");
								return;
							}
				      } 
				});
				
			});	
		</script>

	<script src="<%=basePath %>background/static/admin/layui/layui.js"
		type="text/javascript" charset="utf-8"></script>


	<script>
			//Demo
			layui.use(['form'], function() {
				var form = layui.form();
				form.render();
				//监听提交
				form.on('submit(formDemo)', function(data) {
					layer.msg(JSON.stringify(data.field));
					return false;
				});
			})
		</script>




</body>

</html>